<template>
    <div>
        <ul class="goods-list"
            v-infinite-scroll="loadMore"
            infinite-scroll-disabled="loading"
            infinite-scroll-distance="10"
            :infinite-scroll-immediate-check="true">
            <li v-for="(item,index) in list" class="goods-item" :key="index">
                <router-link :to='`/goods_details/${item.id}`'>
                    <img :src="item.cover" :alt="item.goods_name">
                    <h5>{{item.goods_name}}</h5>
                    <p>兑换积分：<span>{{item.scores}}分</span></p>
                </router-link>
            </li>
        </ul>
        <p class="page-infinite-loading" v-show="loading">
            <mt-spinner type="fading-circle" color="#23ab1b" class="spinner"></mt-spinner>
            加载中...
        </p>
        <p class="no-data" v-if="!loading&&this.list.length===0">暂无商品</p>
        <p class="no-data" v-if="noMore&&this.list.length>0">没有更多了</p>
    </div>
</template>

<script>
export default {
  name: "goods-list",
  props: {
    loading: {
      type:Boolean,
      default:false
    },
    noMore: {
      type:Boolean,
      default:false
    },
    list: {
      type:Array,
      default(){
        return []
      }
    }
  },
  data() {
    return {
      
    };
  },
  mounted() {},
  methods: {
    loadMore() {
      this.$emit('load-more')
    }
  }
};
</script>
<style lang="scss" scoped>
.goods-list {
  margin: 10px 0;
  padding: 0 15px;
  font-size: 0;
  li.goods-item {
    display: inline-block;
    width: 50%;
    padding: 10px 5px;
    border-bottom: 1px solid #d2d2d2;
    box-sizing: border-box;
    a {
      display: block;
      color: #333;
      img {
        width: 100%;
        height: calc((50vw - 20px) * 0.74);
        object-fit: cover;
      }
      h5 {
        font-size: 16px;
        line-height: 30px;
        font-weight: 400;
      }
      p {
        font-size: 13px;
        span {
          color: #ff5a5a;
        }
      }
    }
  }
  li.goods-item:nth-child(odd) {
    padding-left: 0;
    border-right: 1px solid #d2d2d2;
  }
  li.goods-item:nth-child(even) {
    padding-right: 0;
  }
  li.goods-item:nth-last-child(2):not(:nth-child(even)),
  li.goods-item:last-child {
    border-bottom: none;
  }
}
.page-infinite-loading {
  text-align: center;
  line-height: 37px;
  .spinner {
    display: inline-block;
    width: 28px;
    vertical-align: middle;
  }
}
.no-data{
  padding: 10px;
  text-align: center;
  color: #666;
}
</style>


